<template>
	<view @click="urlPost()">
		<slot></slot>
	</view>
</template>

<script>
	export default {
		name: "gt-post",
		props: {
			url: {
				type: String,
				default: function() {
					return ''
				}
			},
			reload: {
				type: [Boolean,String],
				default: function() {
					return ''
				}
			},
			data: {
				type: Object,
				default: function() {
					return {};
				}
			},
			confirm: {
				type: String,
				default: '确认操作'
			}
		},
		data() {
			return {}
		},
		created() {

		},
		// mounted() {
  //           this.$emit('after')
  //       },
		computed: {},
		methods: {
			urlPost() {
				if (this.url) {
					var _this = this;
					if (this.confirm != '') {
						uni.showModal({
							content: _this.$t(_this.confirm),
							cancelText:_this.$t('取消'),
							confirmText:_this.$t('确认'),
							success(e) {
								if (e.confirm == true) {
						_this.apiProcess()
								}

							}
						})
					} else {
						_this.apiProcess()
					}
				}
			},
			apiProcess(){
				var _this = this;
					_this.$post({
						url: _this.url,
						data: _this.data,
						afterFun(resp){
							if(_this.reload){
								_this.$var.reload[_this.reload] = true;
							}
							
							_this.$emit("success");
						}
					});
			}
		}
	}
</script>

<style scoped>

</style>
